<?php

namespace app\admin\controller\stock;

use app\common\controller\Backend;

/**
 * 日K线数据管理
 *
 * @icon fa fa-circle-o
 */
class K extends Backend
{

    /**
     * K模型对象
     * @var \app\admin\model\stock\K
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\stock\K;
        $this->view->assign("adjustflagList", $this->model->getAdjustflagList());
        $this->view->assign("tradestatusList", $this->model->getTradestatusList());
        $this->view->assign("isstList", $this->model->getIsstList());
    }

    /**
     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
     */


    public function detail($code)
    {
        $list = collection(Model("\app\admin\model\stock\K")
            ->where("code = '" . $code . "'")
            ->order('id desc')
            ->field('date, open, close, low, high')
            ->limit(300)
            ->select())->toArray();

        $list = array_reverse($list);
//        $klist = array_values($list);//这样不对
        foreach ($list as $k) {
            $klist[] = array(
//                str_replace("-", "/", $k['date']), //日期怎么表示都可以
                $k['date'],
                floatval($k['open']),
                floatval($k['close']),
                floatval($k['low']),
                floatval($k['high'])
            );
        }

        //当日成本线
        $dflist = collection(Model("\app\admin\model\stock\Dfk")
            ->where("code = '" . $code."'")
            ->order('id desc')
            ->limit(1)
            ->select())->toArray();

        $df = array("", "", "", "");

        foreach ($dflist as $d) {
            $df = array(
                $d['date'],
                "机构参与度".$d['jgcy']."% 主力".$d['kpflag'],
                "主力净流入".$d['zlr']." 超大单流入".$d['clr'],
                "主力成本 ".$d['zc20']." 元"
            );
            break;
        }

        $this->view->assign([
            'klist' => $klist,
            'df' => $df,
            'code' => $code
        ]);

        return $this->view->fetch();
    }


}
